package org.dreamfly.core.dao.impl;

import org.dreamfly.core.bean.SzPictureType;
import org.dreamfly.core.dao.PictureTypeDAO;
import org.dreamfly.core.util.HTMLInputFilter;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import java.util.List;

import static org.hibernate.criterion.Restrictions.like;

/**
 * Created by IntelliJ IDEA.
 * User: Gin
 * Date: 2010-9-18
 * Time: 10:47:29
 * To change this template use File | Settings | File Templates.
 */
public class PictureTypeDAOImpl extends BaseDAOImpl<SzPictureType,Long> implements PictureTypeDAO {

    @Override
    public List<SzPictureType> findAllByServer(String serverName) {
        Criteria criteria=this.getSession().createCriteria(SzPictureType.class);
		criteria.add(like("server",serverName));
        return criteria.list();
    }

    @Override
    public void modifyName(SzPictureType pictureType) {
        HTMLInputFilter inputFilter = new HTMLInputFilter();
		Session session = this.getSession();
		Transaction tx = session.beginTransaction();

		SzPictureType SzpictureType = (SzPictureType) session.load(SzPictureType.class, pictureType.getTypeId());
        SzpictureType.setName(inputFilter.filter(pictureType.getName()));

        tx.commit();
		session.flush();
    }
}
